<?php
require('session.php');

if (empty($_GET['realm'])||empty($_GET['char']))
{
	header('Location: index.php');
}

//db connect
require "connect_pdo.php";
require "classes.php";

//Check if logged in
include 'loginoptional.php';
//set character variables
$realm = $_GET['realm'];
$char = $_GET['char'];
//fix for realms with ' in name
$realm = stripslashes($realm);

$pdo = new pdo_query;
include 'functions.php';
include 'vars.php';

echo "<p>";
echo $armoryUrl;
echo "<br/>";
echo "<br/>";

echo "Character stats: " . "<br/>";
echo "<a class='reg' href='index.php?char=" . $char . "&realm=" . $realm . "'>Back</a>";
//http://www.allmyrandomstuff.com/wow/index.php?char=mightybob&realm=Magtheridon
echo "<table>";
echo "<tr>" . "<th>" . "Character name: " . "</th><th>" . $name . "</th></tr>";

echo build_row('Health',$health,'','','Typically the majority of health comes from stamina bonuses');
//bar stats
echo build_row($bartype,$mana,'','','The majority of mana comes from intellect bonuses');
echo build_row('Regen',$regen_nocombat,'','','Mana regenerated every 5 seconds out of combat');
echo build_row('Combat regen',$regen_combat,'','','Mana regenerated every 5 seconds in combat');

//function build_row($name, $stat, $op, $per, $title)
//function build_row_hi($name, $stat, $op, $items, $title, $section)

//armour
//echo build_row_hi('Armo(u)r',$armor_base,'',$armor_items,'','section1');
echo build_row('Armo(u)r',$armor,'','','','section1');
//echo "<tbody id='section1' style='display:none' onMouseOut=\"displayRow('none','section1')\">";
//echo build_row('Damage absorption',round($armor_dmg_absorb),'','','');
//echo build_row('Damage reduction',$armor_percent,'+','%','');
//echo build_row('Pet bonus', $armor_pet, '+','','');
//echo "</tbody>";

//strength
//echo build_row_hi('Strength',$strength_base,'',$strength_items,'Strength improves attack power and block rating','section2');
//echo "<tbody id='section2' style='display:none'>";
echo build_row('Strength',$strength,'','','Strength improves attack power and block rating','section2');
//echo build_row('Attack power',$strength_att,'+','','AP increases DPS by 1 for each 14 AP');
//echo build_row('Block', $strength_blk,'+','','');
//echo "</tbody>";

//agility
//echo build_row_hi('Agility',$agility_base,'+',$agility_items,'Agility increases AP, armor, crit% and dodge','section3');
echo build_row('Agility',$agility,'','','Agility increases AP, armor, crit% and dodge','section3');
/*
echo "<tbody id='section3' style='display:none'>";
echo build_row('Armo(u)r',$agility_armor,'+','','');
echo build_row('Attack power',$agility_att,'+','','');
echo build_row('Crit chance',$agility_crit,'+','%','');
echo "</tbody>";
*/

//stamina
echo build_row('Stamina',$stamina,'','','Stamina increases health','section4');
/*
echo build_row_hi('Stamina',$stamina_base,'+',$stamina_items,'Stamina increases health','section4');
echo "<tbody id='section4' style='display:none'>";
echo build_row('Health',$stamina_health,'+','','');
echo build_row('Pet bonus',$stamina_pet, '+','','');
echo "</tbody>";
*/

//intellect
if ($bartype=='mana')
{
	echo build_row('Intellect',$intellect,'','','Intellect increases Mana and spell power. The square root of intellect affects mana regeneration','section5');
	/*
echo build_row_hi('Intellect',$intellect_base,'+',$intellect_items,'Intellect increases Mana. The square root of intellect affects mana regeneration','section5');
echo "<tbody id='section5' style='display:none'>";
echo build_row('Spell crit chance',$intellect_crit,'+','%','');
echo build_row('Mana',$intellect_mana, '+','','');
echo build_row('Pet bonus', $intellect_pet, '+', '','');
echo "</tbody>";
*/
}

//spirit
echo build_row('Spirit',$spirit,'','','Spirit is the main characteristic for health & mana regeneration','section6');
/*
echo build_row_hi('Spirit',$spirit_base,'+',$spirit_items,'Spirit is the main characteristic for health & mana regeneration','section6');
echo "<tbody id='section6' style='display:none'>";
echo build_row('Health',$spirit_health,'+','','');
echo build_row('Mana', $spirit_mana, '+','','');
echo "</tbody>";
*/



//more stats
//add notes as titles on certain ones. May have to do this as a comment field in the row

echo "</table></p>";
$k=1;
while ($k<=2)
{
//loop for each specialization
$talent = ${talent.$k};

//queries for stat priorities
$sqlGetPriorities = "SELECT stat.name, comment FROM stat_priority, stat WHERE stat_priority.stat_id = stat.stat_id AND
specialization_id in (select specialization_id FROM specialization WHERE name like ? and class_id = ?) AND pvp_flag=0 ORDER BY stat_priority_id, priority";

$sqlGetPriorities2 = "SELECT stat.name, comment FROM stat_priority, stat WHERE stat_priority.stat_id = stat.stat_id AND
specialization_id in (select specialization_id FROM specialization WHERE name like ? and class_id = ?) AND pvp_flag=1 ORDER BY priority, stat_priority_id";

echo "<p class='footnote'>";
echo "Stat priorities for $talent. Hover over text for any additional comments<br/><br/>";

$pdo->bound_query($sqlGetPriorities,array($talent,$classid),'All');
$result = $pdo->result;
$rows_affected = $pdo->rowcount;
/*
$STH = $DBH->prepare($sqlGetPriorities);
$STH->execute();
$result = $STH->fetchAll();
$rows_affected = $STH->rowCount();
*/
$pdo->bound_query($sqlGetPriorities2,array($talent,$classid),'All');

/*
$STH = $DBH->prepare($sqlGetPriorities2);
$STH->execute();
*/
$result2 = $pdo->result;
$rows_affected2 = $pdo->rowcount;

$i=0;
$j=$rows_affected;
//show stat priorities for pve
echo "Stat priorities for PVE: ";
if ($rows_affected>11)
	{echo "Druid bear form and cat form listed separately<br/>";}
foreach ($result as $statPriority)
{
	echo "<span class='stats' title='".$statPriority[1]."'>".$statPriority[0]."</span>";
	if ($i<($j-1)&&($statPriority[0]<8))
		{echo " > ";}
	if ($i==7)
	{echo "<br/>";}
	
	$i++;
}
echo "<br/>";

$i=0;
$j=$rows_affected2;

//show stat priorities for pvp
echo "Stat priorities for PVP: ";
foreach ($result2 as $statPriority)
{
	echo "<span class='stats' title='".$statPriority[1]."'>".$statPriority[0]."</span>";
	if ($i<($j-1))
		{echo " > ";}
	$i++;
}

echo "</p>";

$k++;
}
echo "<br/>";
echo "<br/>";

include 'footer.html';
?>
